#!/usr/local/bin/ruby
# 
#  getUbiotaWordLists.rb
#   get word lists for each rank from uBiota MySQL database
#  
#  2007-10-09
#  
#  Indra Neil Sarkar, PhD
#  MBLWHOI Library
#  Marine Biological Laboratory
#  7 MBL Street
#  Woods Hole, MA 02543 USA
#  sarkar@mbl.edu
#  
#  
#  Copyright 2007 Marine Biological Laboratory. All rights reserved.
# 

require 'mysql'

ubiota   = Mysql::new("localhost","root","","ubiota")
rankValueString = Array.new
rankValueString[0] = "kingdom"
rankValueString[1] = "phylum"
rankValueString[2] = "class"
rankValueString[3] = "order"
rankValueString[4] = "family"
rankValueString[5] = "genus"
rankValueString[6] = "species"

for rankValue in 0..6
  rankedListFileName = '../morphanalysis/rankLists/' + rankValueString[rankValue] + '.rankList.txt'
  rankedListFile = File.open(rankedListFileName, "w")
  ubiota.query("select TERM from UBT_TERM where rank=#{rankValue} and hierarchy not like 'Viruses%'").each do |termName|
    rankedListFile.puts termName.to_s.gsub(/^.*\s/,"")
  end
  rankedListFile.close
end